//
//  Level.m
//  ToucheTouche
//
//  Created by Jordan Montel on 13/01/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "Level.h"

@implementation Level

@synthesize floatScore, floatScoreToAdd, floatScoreForExtra, floatLife, floatLifeToRemove, floatLifeProgress, floatLifeProgressToRemove, floatExtraScore;
@synthesize intTimeLevel, intTimeLevelToRemove, intCurrentLevel;
@synthesize timeImage;
@synthesize colorBackground;
@synthesize fileImageName;

static Level *sharedLevelManager = nil;



// init : score, score to add, score for extra, life, life to remove, lifeprogress, lifeprogress to remove, time level, time level to remove, current level, time image, background, image
- (void)initLevel:(float)initFloatScore:(float)initFloatScoreToAdd:(float)initFloatScoreForExtra:(float)initFloatLife:(float)initFloatLifeToRemove:(float)initFloatLifeProgress:(float)initFloatLifeProgressToRemove:(NSInteger)initIntTimeLevel:(NSInteger)initTimeLevelToRemove:(NSInteger)initCurrentLevel:(NSTimeInterval)initTimeImage:(NSString *)fileBackground:(NSString *)fileImage {
    
    // init variable
    floatScore = initFloatScore;
    floatScoreToAdd = initFloatScoreToAdd;
    floatScoreForExtra = initFloatScoreForExtra;
    floatLife = initFloatLife;
    floatLifeToRemove = initFloatLifeToRemove;
    floatLifeProgress = initFloatLifeProgress;
    floatLifeProgressToRemove = initFloatLifeProgressToRemove;
    intTimeLevel = initIntTimeLevel;
    intTimeLevelToRemove = initTimeLevelToRemove;
    intCurrentLevel = initCurrentLevel;
    timeImage = initTimeImage;
    
    colorBackground = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:fileBackground]];
    fileImageName = fileImage;
    
    // appel fonction
    [self setIntTimeLevel:intTimeLevel];
    [self removeTimeLevel:intTimeLevelToRemove];
}


- (void)initExtraScore:(float)initExtraScore {
    floatExtraScore = initExtraScore;
}


- (void)addScore:(float)floatScoreToAddFC {
    floatScore += floatScoreToAddFC;
}

- (void)removeLife:(float)floatLifeToRemoveFC :(float)floatLifeProgressToRemoveFC {
    floatLifeProgress = floatLife/100 - floatLifeProgressToRemoveFC; // le progress view est initialise a 1.0
    floatLife -= floatLifeToRemoveFC;
}

- (void)addLife:(float)floatLifeToAdd :(float)floatLifeProgressToAdd {
    floatLifeProgress = floatLife/100 + floatLifeProgressToAdd; // le progress view est initialise a 1.0
    floatLife += floatLifeToAdd;
}

- (void)setIntTimeLevel:(NSInteger)intSetTimeLevel {
    intTimeLevel = intSetTimeLevel;
}

- (void)removeTimeLevel:(NSInteger)intRemoveTimeLevel {
    intTimeLevel -= intRemoveTimeLevel;
}

+ (Level *)sharedLevel {
    if (sharedLevelManager == nil) {
        sharedLevelManager = [[super allocWithZone:nil] init];
    }
    return sharedLevelManager;
}

- (id)init {
    if (self = [super init]) {
        /* float */
        floatScore = 0;
        floatScoreToAdd = 5;
        floatLife = 100;
        floatLifeToRemove = 5;
        floatLifeProgress = 1;
        floatLifeProgressToRemove = 0.05;
        
        /* NSInteger */
        intCurrentLevel = 1;
        intTimeLevel = 10;
        intTimeLevelToRemove = 1;
        
        /* NSTimeInterval */
        timeImage = 1;
    }
    return self;
}




- (void)dealloc {
    [super dealloc];
}

- (id)copyWithZone:(NSZone *)zone {
    return  self;
}

- (id)retain {
    return self;
}

- (NSUInteger)retainCount {
    return NSUIntegerMax;
}

- (id)autorelease {
    return self;
}


@end
